@extends("admin.base.base")
@section("title")
<title>新增文章 - 资讯管理 - H-ui.admin v3.1</title>
<meta name="keywords" content="H-ui.admin v3.1,H-ui网站后台模版,后台模版下载,后台管理系统模版,HTML后台模版下载">
<meta name="description" content="H-ui.admin v3.1，是一款由国人开发的轻量级扁平化网站后台模板，完全免费开源的网站后台管理系统模版，适合中小型CMS后台系统。">
@endsection
@section("content")
<article class="page-container">
	<form class="form form-horizontal" id="form-article-add">
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>栏目名称：</label>
			<div class="formControls col-xs-4 col-sm-4">
				<input type="text" class="input-text" value="{{$res->title}}" placeholder="" id="articletitle" name="title">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>上级分类：</label>
			<div class="formControls col-xs-1 col-sm-1"> <span class="select-box">
				<select name="articlecolumn" class="select" id="sel">
					<option value="0">顶级分类</option>
					@foreach($data as $datas)
					<option value="{{$datas->id}}" <?php if ($datas->id == $res->id) echo 'selected';?>>
						{{$datas->title}}
						@foreach($item as $items)
							@if($datas->id == $items->two_level)
								<option value="100" id="two_level" <?php if ($res->id == $datas->id) echo 'selected = selected';?>>&nbsp;&nbsp;&nbsp;&nbsp;{{$items->title}}</option>
							@endif
						@endforeach
					</option>
					@endforeach
				</select>
				</span> </div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">排序值：</label>
			<div class="formControls col-xs-4 col-sm-4">
				<input type="text" class="input-text" value="{{$res->order}}" placeholder="" id="articlesort" name="articlesort">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">是否显示在导航栏：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<div class="form-check form-check-inline">
					<label class="form-check-label" for="inlineRadio1">
						<input class="form-check-input" type="radio" name="inlineRadioOptions" id="inlineRadio1" value="{{$res->is_display}}" <?php if ($res->is_display == 1) echo 'checked="checked"';?>>是
					</label>
					<label class="form-check-label" for="inlineRadio2">
						<input class="form-check-input" type="radio" name="inlineRadioOptions" id="inlineRadio2"  value="{{$res->is_display}}" <?php if ($res->is_display == 2) echo 'checked="checked"';?>>否
					</label>
				</div>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">关键词：</label>
			<div class="formControls col-xs-4 col-sm-5">
				<input type="text" class="input-text" value="{{$res->keywords}}" placeholder="" id="keywords" name="keywords">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">描述：</label>
			<div class="formControls col-xs-7 col-sm-7">
				<textarea name="abstract" cols="" rows="" class="textarea"  placeholder="说点什么...最少输入10个字符" datatype="*10-100" dragonfly="true" nullmsg="备注不能为空！" onKeyUp="$.Huitextarealength(this,200)">{{$res->description}}</textarea>
			</div>
		</div>
		{{csrf_field()}}
		{{method_field('PUT')}}
		<div class="row cl">
			<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-2">
				<button onClick="article_save();" class="btn btn-secondary radius" type="button"><i class="Hui-iconfont">&#xe632;</i>确定提交</button>
				<button onClick="removeIframe();" class="btn btn-default radius" type="button">&nbsp;&nbsp;取消&nbsp;&nbsp;</button>
			</div>
		</div>
	</form>
</article>
@endsection
@section("js")
<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="{{asset('lib/My97DatePicker/4.8/WdatePicker.js')}}"></script>
<script type="text/javascript" src="{{asset('lib/jquery.validation/1.14.0/jquery.validate.js')}}"></script>
<script type="text/javascript" src="{{asset('lib/jquery.validation/1.14.0/validate-methods.js')}}"></script>
<script type="text/javascript" src="{{asset('lib/jquery.validation/1.14.0/messages_zh.js')}}"></script>
<script type="text/javascript" src="{{asset('lib/webuploader/0.1.5/webuploader.min.js')}}"></script>
<script type="text/javascript" src="{{asset('lib/ueditor/1.4.3/ueditor.config.js')}}"></script>
<script type="text/javascript" src="{{asset('lib/ueditor/1.4.3/ueditor.all.min.js')}}"> </script>
<script type="text/javascript" src="{{asset('lib/ueditor/1.4.3/lang/zh-cn/zh-cn.js')}}"></script>
<script type="text/javascript">
    $("#sel").on('change',function () {
        var value = $(this).children('option:selected').val();
        if (value == 100){
            layer.msg('当前只能创建二级菜单，请重新选择吧！');
		}
    })


function article_save() {
	var data = $("#form-article-add").serializeArray();
	$.ajax({
		type:'POST',
		url:'{{url('admin/classify/'.$res->id)}}',
		data:data,
		dataType:'json',
		success:function (resp) {
			if (resp.code == 0){
			    layer.msg(resp.msg);
			    setTimeout(function () {
					window.location.href = '{{url('admin/classify')}}';
                },1000);
			}else{
			    layer.msg(resp.msg);
			}
        }
	});
}
$(function(){
	$('.skin-minimal input').iCheck({
		checkboxClass: 'icheckbox-blue',
		radioClass: 'iradio-blue',
		increaseArea: '20%'
	});
	
	//表单验证
	$("#form-article-add").validate({
		rules:{
			articletitle:{
				required:true,
			},
			articletitle2:{
				required:true,
			},
			articlecolumn:{
				required:true,
			},
			articletype:{
				required:true,
			},
			articlesort:{
				required:true,
			},
			keywords:{
				required:true,
			},
			abstract:{
				required:true,
			},
			author:{
				required:true,
			},
			sources:{
				required:true,
			},
			allowcomments:{
				required:true,
			},
			commentdatemin:{
				required:true,
			},
			commentdatemax:{
				required:true,
			},

		},
		onkeyup:false,
		focusCleanup:true,
		success:"valid",
		submitHandler:function(form){
			//$(form).ajaxSubmit();
			var index = parent.layer.getFrameIndex(window.name);
			//parent.$('.btn-refresh').click();
			parent.layer.close(index);
		}
	});
});
</script>
@endsection